package modules
{
import flash.display.DisplayObject;
import flash.display.MovieClip;
import flash.errors.IllegalOperationError;
import flash.utils.Dictionary;

import framework.core.ComponentBuilder;
import framework.core.UIWidget;
import framework.proxy.IComponentProxy;

import modules.interfaces.ISectionModule;

import view.interfaces.IBottomUI;
import view.interfaces.ILeftUI;
import view.interfaces.IRightUI;
import view.interfaces.ITopUI;
import view.interfaces.IWorldContainer;

/**
 * SectionModuleBase
 * @author jliang
 *
 */
public class SectionModuleBase extends ModuleBase implements ISectionModule
{
    //==========================================================================
    //  Constructor
    //==========================================================================
    public function SectionModuleBase()
    {
        super();
    }
    //==========================================================================
    //  Variables
    //==========================================================================
    protected var proxys:Dictionary = new Dictionary(true);   /* IComponentProxy */
    
    protected function get topUIReference():Class
    {
        throw new IllegalOperationError("topUIReference getter should be overrided.");
    }
    
    protected function get leftUIReference():Class
    {
        throw new IllegalOperationError("leftUIReference getter should be overrided.");
    }
    
    protected function get rightUIReference():Class
    {
        throw new IllegalOperationError("rightUIReference getter should be overrided.");
    }
    
    protected function get bottomUIReference():Class
    {
        throw new IllegalOperationError("bottomUIReference getter should be overrided.");
    }
    
    protected function get worldContainerReference():Class
    {
        throw new IllegalOperationError("worldContainerReference getter should be overrided.");
    }
    
    protected var skin:MovieClip;
    
    protected function get skinReference():String
    {
        return null;
    }
    //==========================================================================
    //  Properties
    //==========================================================================
    public function get topUI():ITopUI
    {
        return proxys["topUI"];
    }
    
    public function get leftUI():ILeftUI
    {
        return proxys["leftUI"];
    }
    
    public function get rightUI():IRightUI
    {
        return proxys["rightUI"];
    }    
    
    public function get bottomUI():IBottomUI
    {
        return proxys["bottomUI"];
    }
    
    public function get worldContainer():IWorldContainer
    {
        return proxys["worldContainer"];
    }
    
    public function get displayObject():DisplayObject
    {
        return this;
    }
    
    public function resize(widthOffset:Number, heightOffset:Number):void
    {
        
    }
    
    protected function initUI():void
    {
        skin = UIWidget.createUI(skinReference) as MovieClip;
        addChild(skin);
        
        initProxy("topUI", topUIReference, skin["topUI"]);
        initProxy("leftUI", leftUIReference, skin["leftUI"]);
        initProxy("rightUI", rightUIReference, skin["rightUI"]);
        initProxy("bottomUI", bottomUIReference, skin["bottomUI"]);
        initProxy("worldContainer", worldContainerReference, skin["worldContainer"]);
    }
    
    protected function initProxy(id:String, ref:Class, skinMapping:MovieClip):void
    {
        var proxy:IComponentProxy = ComponentBuilder.create(ref) as IComponentProxy;
        proxy.id= id;
        proxy.parse(skinMapping);
        proxys[proxy.id] = proxy;
    }
}
}






